using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Data.Common;
using System.Diagnostics;
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Security.Permissions;
using System.Threading;
using System.Web;

namespace PickGold.Charting
{
	[SRDescription("DescriptionAttributeDataPointCollection_DataPointCollection")]
	[AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
	[AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
	public class DataPointCollection : ChartElementCollection<DataPoint>
	{
		internal Series series;

		internal DataPointCollection(Series series)
			: base(series)
		{
			this.series = series;
		}

		public DataPoint Add(params double[] y)
		{
			DataPoint item = new DataPoint(0.0, y);
			base.Add(item);
			return item;
		}

		public int AddXY(double xValue, double yValue)
		{
			DataPoint dataPoint = new DataPoint(this.series);
			dataPoint.SetValueXY(xValue, new object[] { yValue });
			this.DataPointInit(ref dataPoint);
			base.Add(dataPoint);
			return (base.Count - 1);
		}

		public int AddXY(object xValue, params object[] yValue)
		{
			if (this.series.XValueType == ChartValueType.Auto)
			{
				if (xValue is DateTime)
				{
					this.series.XValueType = ChartValueType.DateTime;
				}
				if (xValue is DateTimeOffset)
				{
					this.series.XValueType = ChartValueType.DateTimeOffset;
				}
				if (xValue is string)
				{
					this.series.XValueType = ChartValueType.String;
				}
				this.series.autoXValueType = true;
			}
			if (((this.series.YValueType == ChartValueType.Auto) && (yValue.Length > 0)) && (yValue[0] != null))
			{
				if (yValue[0] is DateTime)
				{
					this.series.YValueType = ChartValueType.DateTime;
					this.series.autoYValueType = true;
				}
				else if (yValue[0] is DateTimeOffset)
				{
					this.series.YValueType = ChartValueType.DateTimeOffset;
					this.series.autoYValueType = true;
				}
			}
			DataPoint dataPoint = new DataPoint(this.series);
			dataPoint.SetValueXY(xValue, yValue);
			this.DataPointInit(ref dataPoint);
			base.Add(dataPoint);
			return (base.Count - 1);
		}

		public int AddY(params object[] yValue)
		{
			if ((yValue == null) || ((yValue.Length == 1) && (yValue[0] == null)))
			{
				throw new ArgumentNullException("yValue");
			}
			if (((this.series.YValueType == ChartValueType.Auto) && (yValue.Length > 0)) && (yValue[0] != null))
			{
				if (yValue[0] is DateTime)
				{
					this.series.YValueType = ChartValueType.DateTime;
					this.series.autoYValueType = true;
				}
				else if (yValue[0] is DateTimeOffset)
				{
					this.series.YValueType = ChartValueType.DateTimeOffset;
					this.series.autoYValueType = true;
				}
			}
			DataPoint dataPoint = new DataPoint(this.series);
			dataPoint.SetValueY(yValue);
			this.DataPointInit(ref dataPoint);
			base.Add(dataPoint);
			return (base.Count - 1);
		}

		public int AddY(double yValue)
		{
			DataPoint dataPoint = new DataPoint(this.series);
			dataPoint.SetValueY(new object[] { yValue });
			this.DataPointInit(ref dataPoint);
			base.Add(dataPoint);
			return (base.Count - 1);
		}

		internal static void AutoDetectValuesType(Series series, IEnumerator xEnumerator, string xField, IEnumerator yEnumerator, string yField)
		{
			if (series.XValueType == ChartValueType.Auto)
			{
				series.XValueType = GetValueType(xEnumerator, xField);
				if (series.XValueType != ChartValueType.Auto)
				{
					series.autoXValueType = true;
				}
			}
			if (series.YValueType == ChartValueType.Auto)
			{
				series.YValueType = GetValueType(yEnumerator, yField);
				if (series.YValueType != ChartValueType.Auto)
				{
					series.autoYValueType = true;
				}
			}
		}

		internal static object ConvertEnumerationItem(object item, string fieldName)
		{
			object obj2 = item;
			DataRow row = item as DataRow;
			if (row != null)
			{
				if ((fieldName != null) && (fieldName.Length > 0))
				{
					bool flag = true;
					if (row.Table.Columns.Contains(fieldName))
					{
						obj2 = row[fieldName];
						flag = false;
					}
					else
					{
						int num;
						flag = !int.TryParse(fieldName, NumberStyles.Any, CultureInfo.InvariantCulture, out num);
						if ((!flag && (num < row.Table.Columns.Count)) && (num >= 0))
						{
							obj2 = row[num];
						}
					}
					if (flag)
					{
						throw new ArgumentException(SR.ExceptionColumnNameNotFound(fieldName));
					}
				}
				else
				{
					obj2 = row[0];
				}
			}
			DataRowView view = item as DataRowView;
			if (view != null)
			{
				if ((fieldName != null) && (fieldName.Length > 0))
				{
					bool flag2 = true;
					if (view.DataView.Table.Columns.Contains(fieldName))
					{
						obj2 = view[fieldName];
						flag2 = false;
					}
					else
					{
						int num2;
						flag2 = !int.TryParse(fieldName, NumberStyles.Any, CultureInfo.InvariantCulture, out num2);
						if ((!flag2 && (num2 < view.DataView.Table.Columns.Count)) && (num2 >= 0))
						{
							obj2 = view[num2];
						}
					}
					if (flag2)
					{
						throw new ArgumentException(SR.ExceptionColumnNameNotFound(fieldName));
					}
				}
				else
				{
					obj2 = view[0];
				}
			}
			DbDataRecord record = item as DbDataRecord;
			if (record != null)
			{
				if ((fieldName == null) || (fieldName.Length <= 0))
				{
					return record[0];
				}
				bool flag3 = true;
				if (!char.IsNumber(fieldName, 0))
				{
					try
					{
						obj2 = record[fieldName];
						flag3 = false;
					}
					catch (IndexOutOfRangeException)
					{
						flag3 = true;
					}
				}
				if (flag3)
				{
					try
					{
						int num3;
						if (int.TryParse(fieldName, NumberStyles.Any, CultureInfo.InvariantCulture, out num3))
						{
							obj2 = record[num3];
							flag3 = false;
						}
						else
						{
							flag3 = true;
						}
					}
					catch (IndexOutOfRangeException)
					{
						flag3 = true;
					}
				}
				if (flag3)
				{
					throw new ArgumentException(SR.ExceptionColumnNameNotFound(fieldName));
				}
				return obj2;
			}
			if ((fieldName == null) || (fieldName.Length <= 0))
			{
				return obj2;
			}
			PropertyDescriptor descriptor = TypeDescriptor.GetProperties(item).Find(fieldName, true);
			if (descriptor == null)
			{
				return obj2;
			}
			return (descriptor.GetValue(item) ?? null);
		}

		public void DataBind(IEnumerable dataSource, string xField, string yFields, string otherFields)
		{
			if (dataSource == null)
			{
				throw new ArgumentNullException("dataSource", SR.ExceptionDataPointInsertionNoDataSource);
			}
			if (dataSource is string)
			{
				throw new ArgumentException(SR.ExceptionDataBindSeriesToString, "dataSource");
			}
			if (yFields == null)
			{
				throw new ArgumentNullException("yFields");
			}
			string[] strArray = yFields.Replace(",,", "\n").Split(new char[] { ',' });
			for (int i = 0; i < strArray.Length; i++)
			{
				strArray[i] = strArray[i].Replace("\n", ",");
			}
			if (strArray.GetLength(0) > this.series.YValuesPerPoint)
			{
				throw new ArgumentOutOfRangeException("yFields", SR.ExceptionDataPointYValuesCountMismatch(this.series.YValuesPerPoint.ToString(CultureInfo.InvariantCulture)));
			}
			string[] otherAttributeNames = null;
			string[] otherFieldNames = null;
			string[] otherValueFormat = null;
			ParsePointFieldsParameter(otherFields, ref otherAttributeNames, ref otherFieldNames, ref otherValueFormat);
			base.Clear();
			IEnumerator dataSourceEnumerator = GetDataSourceEnumerator(dataSource);
			if (dataSourceEnumerator.GetType() != typeof(DbEnumerator))
			{
				dataSourceEnumerator.Reset();
			}
			bool flag = true;
			object[] yValue = new object[strArray.Length];
			object val = null;
			bool flag2 = true;
			this.SuspendUpdates();
			try
			{
				do
				{
					if (flag)
					{
						flag = dataSourceEnumerator.MoveNext();
					}
					if (flag2)
					{
						flag2 = false;
						AutoDetectValuesType(this.series, dataSourceEnumerator, xField, dataSourceEnumerator, strArray[0]);
					}
					if (flag)
					{
						DataPoint dataPoint = new DataPoint(this.series);
						bool flag3 = false;
						if (xField.Length > 0)
						{
							val = ConvertEnumerationItem(dataSourceEnumerator.Current, xField);
							if (IsEmptyValue(val))
							{
								flag3 = true;
								val = 0.0;
							}
						}
						if (strArray.Length == 0)
						{
							yValue[0] = ConvertEnumerationItem(dataSourceEnumerator.Current, null);
							if (IsEmptyValue(yValue[0]))
							{
								flag3 = true;
								yValue[0] = 0.0;
							}
						}
						else
						{
							for (int j = 0; j < strArray.Length; j++)
							{
								yValue[j] = ConvertEnumerationItem(dataSourceEnumerator.Current, strArray[j]);
								if (IsEmptyValue(yValue[j]))
								{
									flag3 = true;
									yValue[j] = 0.0;
								}
							}
						}
						if ((otherAttributeNames != null) && (otherAttributeNames.Length > 0))
						{
							for (int k = 0; k < otherFieldNames.Length; k++)
							{
								object obj3 = ConvertEnumerationItem(dataSourceEnumerator.Current, otherFieldNames[k]);
								if (!IsEmptyValue(obj3))
								{
									dataPoint.SetPointCustomProperty(obj3, otherAttributeNames[k], otherValueFormat[k]);
								}
							}
						}
						if (flag3)
						{
							if (val != null)
							{
								dataPoint.SetValueXY(val, yValue);
							}
							else
							{
								dataPoint.SetValueXY(0, yValue);
							}
							this.DataPointInit(ref dataPoint);
							dataPoint.IsEmpty = true;
							base.Add(dataPoint);
						}
						else
						{
							if (val != null)
							{
								dataPoint.SetValueXY(val, yValue);
							}
							else
							{
								dataPoint.SetValueXY(0, yValue);
							}
							this.DataPointInit(ref dataPoint);
							base.Add(dataPoint);
						}
					}
				}
				while (flag);
			}
			finally
			{
				this.ResumeUpdates();
			}
		}

		public void DataBindXY(IEnumerable xValue, params IEnumerable[] yValues)
		{
			if ((yValues == null) || ((yValues.Length == 1) && (yValues[0] == null)))
			{
				throw new ArgumentNullException("yValues");
			}
			if (yValues.GetLength(0) == 0)
			{
				throw new ArgumentException(SR.ExceptionDataPointBindingYValueNotSpecified, "yValues");
			}
			for (int i = 0; i < yValues.Length; i++)
			{
				if (yValues[i] is string)
				{
					throw new ArgumentException(SR.ExceptionDataBindYValuesToString, "yValues");
				}
			}
			if (yValues.GetLength(0) > this.series.YValuesPerPoint)
			{
				throw new ArgumentOutOfRangeException("yValues", SR.ExceptionDataPointYValuesBindingCountMismatch(this.series.YValuesPerPoint.ToString(CultureInfo.InvariantCulture)));
			}
			base.Clear();
			IEnumerator xEnumerator = null;
			IEnumerator[] enumeratorArray = new IEnumerator[yValues.GetLength(0)];
			if (xValue != null)
			{
				if (xValue is string)
				{
					throw new ArgumentException(SR.ExceptionDataBindXValuesToString, "xValue");
				}
				xEnumerator = GetDataSourceEnumerator(xValue);
				if (xEnumerator.GetType() != typeof(DbEnumerator))
				{
					xEnumerator.Reset();
				}
			}
			for (int j = 0; j < yValues.Length; j++)
			{
				enumeratorArray[j] = GetDataSourceEnumerator(yValues[j]);
				if (enumeratorArray[j].GetType() != typeof(DbEnumerator))
				{
					enumeratorArray[j].Reset();
				}
			}
			bool flag = false;
			bool flag2 = true;
			object[] yValue = new object[this.series.YValuesPerPoint];
			object obj2 = null;
			bool flag3 = true;
			this.SuspendUpdates();
			try
			{
				do
				{
					flag2 = true;
					for (int k = 0; k < yValues.Length; k++)
					{
						if (flag2)
						{
							flag2 = enumeratorArray[k].MoveNext();
						}
					}
					if (xValue != null)
					{
						flag = xEnumerator.MoveNext();
						if (flag2 && !flag)
						{
							throw new ArgumentOutOfRangeException("xValue", SR.ExceptionDataPointInsertionXValuesQtyIsLessYValues);
						}
					}
					if (flag3)
					{
						flag3 = false;
						AutoDetectValuesType(this.series, xEnumerator, null, enumeratorArray[0], null);
					}
					if (flag || flag2)
					{
						DataPoint dataPoint = new DataPoint(this.series);
						bool flag4 = false;
						if (flag)
						{
							obj2 = ConvertEnumerationItem(xEnumerator.Current, null);
							if ((obj2 is DBNull) || (obj2 == null))
							{
								flag4 = true;
								obj2 = 0.0;
							}
						}
						for (int m = 0; m < yValues.Length; m++)
						{
							yValue[m] = ConvertEnumerationItem(enumeratorArray[m].Current, null);
							if ((yValue[m] is DBNull) || (yValue[m] == null))
							{
								flag4 = true;
								yValue[m] = 0.0;
							}
						}
						if (flag4)
						{
							if (obj2 != null)
							{
								dataPoint.SetValueXY(obj2, yValue);
							}
							else
							{
								dataPoint.SetValueXY(0, yValue);
							}
							this.DataPointInit(ref dataPoint);
							dataPoint.IsEmpty = true;
							base.Add(dataPoint);
						}
						else
						{
							if (obj2 != null)
							{
								dataPoint.SetValueXY(obj2, yValue);
							}
							else
							{
								dataPoint.SetValueXY(0, yValue);
							}
							this.DataPointInit(ref dataPoint);
							base.Add(dataPoint);
						}
					}
				}
				while (flag || flag2);
			}
			finally
			{
				this.ResumeUpdates();
			}
		}

		public void DataBindXY(IEnumerable xValue, string xField, IEnumerable yValue, string yFields)
		{
			if (xValue is string)
			{
				throw new ArgumentException(SR.ExceptionDataBindXValuesToString, "xValue");
			}
			if (yValue == null)
			{
				throw new ArgumentNullException("yValue", SR.ExceptionDataPointInsertionYValueNotSpecified);
			}
			if (yValue is string)
			{
				throw new ArgumentException(SR.ExceptionDataBindYValuesToString, "yValue");
			}
			if (yFields == null)
			{
				throw new ArgumentOutOfRangeException("yFields", SR.ExceptionDataPointYValuesCountMismatch(this.series.YValuesPerPoint.ToString(CultureInfo.InvariantCulture)));
			}
			string[] strArray = yFields.Replace(",,", "\n").Split(new char[] { ',' });
			for (int i = 0; i < strArray.Length; i++)
			{
				strArray[i] = strArray[i].Replace("\n", ",");
			}
			if (strArray.GetLength(0) > this.series.YValuesPerPoint)
			{
				throw new ArgumentOutOfRangeException("yFields", SR.ExceptionDataPointYValuesCountMismatch(this.series.YValuesPerPoint.ToString(CultureInfo.InvariantCulture)));
			}
			base.Clear();
			IEnumerator xEnumerator = null;
			IEnumerator dataSourceEnumerator = GetDataSourceEnumerator(yValue);
			if (dataSourceEnumerator.GetType() != typeof(DbEnumerator))
			{
				dataSourceEnumerator.Reset();
			}
			if (xValue != null)
			{
				if (xValue != yValue)
				{
					xEnumerator = GetDataSourceEnumerator(xValue);
					if (xEnumerator.GetType() != typeof(DbEnumerator))
					{
						xEnumerator.Reset();
					}
				}
				else
				{
					xEnumerator = dataSourceEnumerator;
				}
			}
			bool flag = false;
			bool flag2 = true;
			object[] objArray = new object[strArray.Length];
			object val = null;
			bool flag3 = true;
			this.SuspendUpdates();
			try
			{
				do
				{
					if (flag2)
					{
						flag2 = dataSourceEnumerator.MoveNext();
					}
					if (xValue != null)
					{
						if (xValue != yValue)
						{
							flag = xEnumerator.MoveNext();
							if (flag2 && !flag)
							{
								throw new ArgumentOutOfRangeException("xValue", SR.ExceptionDataPointInsertionXValuesQtyIsLessYValues);
							}
						}
						else
						{
							flag = flag2;
						}
					}
					if (flag3)
					{
						flag3 = false;
						AutoDetectValuesType(this.series, xEnumerator, xField, dataSourceEnumerator, strArray[0]);
					}
					if (flag || flag2)
					{
						DataPoint dataPoint = new DataPoint(this.series);
						bool flag4 = false;
						if (flag)
						{
							val = ConvertEnumerationItem(xEnumerator.Current, xField);
							if (IsEmptyValue(val))
							{
								flag4 = true;
								val = 0.0;
							}
						}
						if (strArray.Length == 0)
						{
							objArray[0] = ConvertEnumerationItem(dataSourceEnumerator.Current, null);
							if (IsEmptyValue(objArray[0]))
							{
								flag4 = true;
								objArray[0] = 0.0;
							}
						}
						else
						{
							for (int j = 0; j < strArray.Length; j++)
							{
								objArray[j] = ConvertEnumerationItem(dataSourceEnumerator.Current, strArray[j]);
								if (IsEmptyValue(objArray[j]))
								{
									flag4 = true;
									objArray[j] = 0.0;
								}
							}
						}
						if (flag4)
						{
							if (val != null)
							{
								dataPoint.SetValueXY(val, objArray);
							}
							else
							{
								dataPoint.SetValueXY(0, objArray);
							}
							this.DataPointInit(ref dataPoint);
							dataPoint.IsEmpty = true;
							base.Add(dataPoint);
						}
						else
						{
							if (val != null)
							{
								dataPoint.SetValueXY(val, objArray);
							}
							else
							{
								dataPoint.SetValueXY(0, objArray);
							}
							this.DataPointInit(ref dataPoint);
							base.Add(dataPoint);
						}
					}
				}
				while (flag || flag2);
			}
			finally
			{
				this.ResumeUpdates();
			}
		}

		public void DataBindY(params IEnumerable[] yValue)
		{
			this.DataBindXY(null, yValue);
		}

		public void DataBindY(IEnumerable yValue, string yFields)
		{
			this.DataBindXY(null, null, yValue, yFields);
		}

		internal void DataPointInit(ref DataPoint dataPoint)
		{
			DataPointInit(this.series, ref dataPoint);
		}

		internal static void DataPointInit(Series series, ref DataPoint dataPoint)
		{
			dataPoint.series = series;
			if ((dataPoint.AxisLabel.Length > 0) && (series != null))
			{
				series.noLabelsInPoints = false;
			}
		}

		public IEnumerable<DataPoint> FindAllByValue(double valueToFind)
		{
			return this.FindAllByValue(valueToFind, "Y");
		}

		public IEnumerable<DataPoint> FindAllByValue(double valueToFind, string useValue)
		{
			return this.Where(item => item.GetValueByName(useValue) == valueToFind);
		}

		public IEnumerable<DataPoint> FindAllByValue(double valueToFind, string useValue, int startIndex)
		{
			return this.Skip(startIndex).Where(item => item.GetValueByName(useValue) == valueToFind);
		}

		public DataPoint FindByValue(double valueToFind)
		{
			return this.FindByValue(valueToFind, "Y");
		}

		public DataPoint FindByValue(double valueToFind, string useValue)
		{
			return this.FindByValue(valueToFind, useValue, 0);
		}

		public DataPoint FindByValue(double valueToFind, string useValue, int startIndex)
		{
			if (useValue == null)
			{
				throw new ArgumentNullException("useValue");
			}
			if ((startIndex < 0) || (startIndex >= base.Count))
			{
				throw new ArgumentOutOfRangeException("startIndex");
			}
			for (int i = startIndex; i < base.Count; i++)
			{
				DataPoint point = base[i];
				if (point.GetValueByName(useValue) == valueToFind)
				{
					return point;
				}
			}
			return null;
		}

		public DataPoint FindMaxByValue()
		{
			return this.FindMaxByValue("Y");
		}

		public DataPoint FindMaxByValue(string useValue)
		{
			return this.FindMaxByValue(useValue, 0);
		}

		public DataPoint FindMaxByValue(string useValue, int startIndex)
		{
			if (useValue == null)
			{
				throw new ArgumentNullException("useValue");
			}
			if ((startIndex < 0) || (startIndex >= base.Count))
			{
				throw new ArgumentOutOfRangeException("startIndex");
			}
			bool flag = useValue.StartsWith("Y", StringComparison.OrdinalIgnoreCase);
			double minValue = double.MinValue;
			DataPoint point = null;
			for (int i = startIndex; i < base.Count; i++)
			{
				DataPoint point2 = base[i];
				if (!point2.IsEmpty || !flag)
				{
					double valueByName = point2.GetValueByName(useValue);
					if (minValue < valueByName)
					{
						minValue = valueByName;
						point = point2;
					}
				}
			}
			return point;
		}

		public DataPoint FindMinByValue()
		{
			return this.FindMinByValue("Y");
		}

		public DataPoint FindMinByValue(string useValue)
		{
			return this.FindMinByValue(useValue, 0);
		}

		public DataPoint FindMinByValue(string useValue, int startIndex)
		{
			if (useValue == null)
			{
				throw new ArgumentNullException("useValue");
			}
			if ((startIndex < 0) || (startIndex >= base.Count))
			{
				throw new ArgumentOutOfRangeException("startIndex");
			}
			bool flag = useValue.StartsWith("Y", StringComparison.OrdinalIgnoreCase);
			double maxValue = double.MaxValue;
			DataPoint point = null;
			for (int i = startIndex; i < base.Count; i++)
			{
				DataPoint point2 = base[i];
				if (!point2.IsEmpty || !flag)
				{
					double valueByName = point2.GetValueByName(useValue);
					if (maxValue > valueByName)
					{
						maxValue = valueByName;
						point = point2;
					}
				}
			}
			return point;
		}

		internal static IEnumerator GetDataSourceEnumerator(IEnumerable dataSource)
		{
			DataView view = dataSource as DataView;
			if (view != null)
			{
				return view.GetEnumerator();
			}
			DataSet set = dataSource as DataSet;
			if ((set != null) && (set.Tables.Count > 0))
			{
				return set.Tables[0].Rows.GetEnumerator();
			}
			return dataSource.GetEnumerator();
		}

		private static ChartValueType GetValueType(IEnumerator enumerator, string field)
		{
			ChartValueType auto = ChartValueType.Auto;
			Type dataType = null;
			if (enumerator != null)
			{
				try
				{
					if (enumerator.Current == null)
					{
						return auto;
					}
				}
				catch (InvalidOperationException)
				{
					return auto;
				}
				if (enumerator.Current is DataRow)
				{
					if ((field != null) && (field.Length > 0))
					{
						bool flag = true;
						if (((DataRow)enumerator.Current).Table.Columns.Contains(field))
						{
							dataType = ((DataRow)enumerator.Current).Table.Columns[field].DataType;
							flag = false;
						}
						if (flag)
						{
							int num;
							if (int.TryParse(field, NumberStyles.Any, CultureInfo.InvariantCulture, out num))
							{
								dataType = ((DataRow)enumerator.Current).Table.Columns[num].DataType;
								flag = false;
							}
							else
							{
								flag = true;
							}
						}
						if (flag)
						{
							throw new ArgumentException(SR.ExceptionColumnNameNotFound(field));
						}
					}
					else if (((DataRow)enumerator.Current).Table.Columns.Count > 0)
					{
						dataType = ((DataRow)enumerator.Current).Table.Columns[0].DataType;
					}
				}
				else if (enumerator.Current is DataRowView)
				{
					if ((field != null) && (field.Length > 0))
					{
						bool flag3 = true;
						if (((DataRowView)enumerator.Current).DataView.Table.Columns.Contains(field))
						{
							dataType = ((DataRowView)enumerator.Current).DataView.Table.Columns[field].DataType;
							flag3 = false;
						}
						if (flag3)
						{
							int num2;
							if (int.TryParse(field, NumberStyles.Any, CultureInfo.InvariantCulture, out num2))
							{
								dataType = ((DataRowView)enumerator.Current).DataView.Table.Columns[num2].DataType;
								flag3 = false;
							}
							else
							{
								flag3 = true;
							}
						}
						if (flag3)
						{
							throw new ArgumentException(SR.ExceptionColumnNameNotFound(field));
						}
					}
					else if (((DataRowView)enumerator.Current).DataView.Table.Columns.Count > 0)
					{
						dataType = ((DataRowView)enumerator.Current).DataView.Table.Columns[0].DataType;
					}
				}
				else if (enumerator.Current is DbDataRecord)
				{
					if ((field != null) && (field.Length > 0))
					{
						bool flag5 = true;
						int i = 0;
						if (!char.IsNumber(field, 0))
						{
							i = ((DbDataRecord)enumerator.Current).GetOrdinal(field);
							dataType = ((DbDataRecord)enumerator.Current).GetFieldType(i);
							flag5 = false;
						}
						if (flag5)
						{
							flag5 = !int.TryParse(field, NumberStyles.Any, CultureInfo.InvariantCulture, out i);
							if (!flag5)
							{
								dataType = ((DbDataRecord)enumerator.Current).GetFieldType(i);
							}
						}
						if (flag5)
						{
							throw new ArgumentException(SR.ExceptionColumnNameNotFound(field));
						}
					}
					else if (((DbDataRecord)enumerator.Current).FieldCount > 0)
					{
						dataType = ((DbDataRecord)enumerator.Current).GetFieldType(0);
					}
				}
				else
				{
					if ((field != null) && (field.Length > 0))
					{
						PropertyDescriptor descriptor = TypeDescriptor.GetProperties(enumerator.Current).Find(field, true);
						if (descriptor != null)
						{
							dataType = descriptor.PropertyType;
						}
					}
					if (dataType == null)
					{
						dataType = enumerator.Current.GetType();
					}
				}
				if (dataType != null)
				{
					if (dataType == typeof(DateTime))
					{
						return ChartValueType.DateTime;
					}
					if (dataType == typeof(DateTimeOffset))
					{
						return ChartValueType.DateTimeOffset;
					}
					if (dataType == typeof(TimeSpan))
					{
						return ChartValueType.Time;
					}
					if (dataType == typeof(double))
					{
						return ChartValueType.Double;
					}
					if (dataType == typeof(int))
					{
						return ChartValueType.Int32;
					}
					if (dataType == typeof(long))
					{
						return ChartValueType.Int64;
					}
					if (dataType == typeof(float))
					{
						return ChartValueType.Single;
					}
					if (dataType == typeof(string))
					{
						return ChartValueType.String;
					}
					if (dataType == typeof(uint))
					{
						return ChartValueType.UInt32;
					}
					if (dataType == typeof(ulong))
					{
						auto = ChartValueType.UInt64;
					}
				}
			}
			return auto;
		}

		internal override void Initialize(DataPoint item)
		{
			this.DataPointInit(ref item);
			base.Initialize(item);
		}

		public void InsertXY(int index, object xValue, params object[] yValue)
		{
			DataPoint dataPoint = new DataPoint(this.series);
			dataPoint.SetValueXY(xValue, yValue);
			this.DataPointInit(ref dataPoint);
			base.Insert(index, dataPoint);
		}

		public void InsertY(int index, params object[] yValue)
		{
			DataPoint dataPoint = new DataPoint(this.series);
			dataPoint.SetValueY(yValue);
			this.DataPointInit(ref dataPoint);
			base.Insert(index, dataPoint);
		}

		internal static bool IsEmptyValue(object val)
		{
			return (((val is DBNull) || (val == null)) || (((val is double) && double.IsNaN((double)val)) || ((val is float) && float.IsNaN((float)val))));
		}

		internal static void ParsePointFieldsParameter(string otherFields, ref string[] otherAttributeNames, ref string[] otherFieldNames, ref string[] otherValueFormat)
		{
			if ((otherFields != null) && (otherFields.Length > 0))
			{
				otherAttributeNames = otherFields.Replace(",,", "\n").Split(new char[] { ',' });
				otherFieldNames = new string[otherAttributeNames.Length];
				otherValueFormat = new string[otherAttributeNames.Length];
				for (int i = 0; i < otherAttributeNames.Length; i++)
				{
					int index = otherAttributeNames[i].IndexOf('=');
					if (index <= 0)
					{
						throw new ArgumentException(SR.ExceptionParameterFormatInvalid, "otherFields");
					}
					otherFieldNames[i] = otherAttributeNames[i].Substring(index + 1);
					otherAttributeNames[i] = otherAttributeNames[i].Substring(0, index);
					int length = otherFieldNames[i].IndexOf('{');
					if ((length > 0) && (otherFieldNames[i][otherFieldNames[i].Length - 1] == '}'))
					{
						otherValueFormat[i] = otherFieldNames[i].Substring(length + 1);
						otherValueFormat[i] = otherValueFormat[i].Trim(new char[] { '{', '}' });
						otherFieldNames[i] = otherFieldNames[i].Substring(0, length);
					}
					otherAttributeNames[i] = otherAttributeNames[i].Trim().Replace("\n", ",");
					otherFieldNames[i] = otherFieldNames[i].Trim().Replace("\n", ",");
				}
			}
		}
	}
}

